import Cookies from 'js-cookie'
import variables from '@/styles/element-variables.scss'
const layout = {
    namespaced: true,
    state:{
       sidebar:{
           opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
            withoutAnimation: false,
       },
       sidebarLogo:true,//展示左侧Logo
       fixedHeader:true,//是否固定header布局
       needTagsView:false,//菜单项置顶
       device: 'desktop',
       isRouterAlive:true,//是否显示组件页面，用于组件页面刷新
       showSetting:false,
       theme:variables.theme
    },
    mutations: {
        TOGGLE_SIDEBAR: state => {
            state.sidebar.opened = !state.sidebar.opened
            state.sidebar.withoutAnimation = false
            if (state.sidebar.opened) {
              Cookies.set('sidebarStatus', 1)
            } else {
              Cookies.set('sidebarStatus', 0)
            }
          },
          CLOSE_SIDEBAR: (state, withoutAnimation) => {
            Cookies.set('sidebarStatus', 0)
            state.sidebar.opened = false
            state.sidebar.withoutAnimation = withoutAnimation
          },
          TOGGLE_DEVICE: (state, device) => {
            state.device = device
          },
          RELOAD_VIEW:(state) => {
              state.isRouterAlive = !state.isRouterAlive
          },
          SHOW_SETTING:(state)=>{
            state.showSetting = true
          },
          CLOSE_SETTING:(state)=>{
            state.showSetting = false
          },
          CHANGE_SETTING: (state, { key, value }) => {
            if (state.hasOwnProperty(key)) {
              state[key] = value
            }
          }
    },
    actions: {
        toggleSideBar({ commit }) {
            commit('TOGGLE_SIDEBAR')
        },
        closeSideBar({ commit }, { withoutAnimation }) {
            commit('CLOSE_SIDEBAR', withoutAnimation)
        },
        toggleDevice({ commit }, device) {
            commit('TOGGLE_DEVICE', device)
        },
        reloadView({commit}) {
            commit('RELOAD_VIEW')
        },
        showSetting({commit}){
          commit('SHOW_SETTING')
        },
        closeSetting({commit}){
          commit('CLOSE_SETTING')
        },
        changeSetting({ commit }, data) {
          commit('CHANGE_SETTING', data)
        }
    }
}
export default layout;